package cn.xuan.zp.service.shiro;

import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.UnauthenticatedException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class ExceptionResolver implements HandlerExceptionResolver {
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object o, Exception e) {
        System.out.println(e.getClass());
        ModelAndView mv = new ModelAndView();
        if(e instanceof IncorrectCredentialsException || 
                e instanceof UnknownAccountException ||
                e instanceof UnauthenticatedException){
            //跳转到登录界面
            mv.setViewName("redirect:/user/login");
        }
        return mv;
    }
}
